package com.example.ribbonconsumer.controller;

import com.example.ribbonconsumer.config.BusinessException;
import com.example.ribbonconsumer.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ConsumerController {

    @Autowired
    private HelloService helloService;

    @RequestMapping(value = "/ribbon-consumer", method = RequestMethod.GET)
    public String helloConsumer() {

        return helloService.helloService();
    }

    @RequestMapping(value = "/test")
    public String test() {

        // 业务处理
        if (true)
            throw new BusinessException("hello","我是异常");
        // ...
        return "test";
    }

    @RequestMapping(value = "/test2")
    public ResponseEntity test2() {
        ResponseEntity re = new ResponseEntity("111", HttpStatus
                .valueOf("222"));
        // 业务处理
        // ...
        if (true)
            throw new RuntimeException("我是异常");


        return re;
    }

}